package com.szh.te.controller;

import cn.hutool.core.date.DateUtil;
import com.szh.te.tcc.AccountTCCService;
import com.szh.zh.vo.DateVo;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.List;

/**
 * @author 虎哥
 */
@RestController
@RequestMapping("account")
public class AccountController {

    // @Resource
    // private AccountService accountService;

    // TCC事务模式处理
    @Resource
    private AccountTCCService accountTCCService;

    @PutMapping("/{userId}/{money}")
    public ResponseEntity<Void> deduct(@PathVariable("userId") String userId, @PathVariable("money") Integer money) {
        accountTCCService.deduct(userId, money);
        return ResponseEntity.noContent().build();
    }

    @GetMapping("/testBody")
    public DateVo testGetRequestBody(@RequestParam List<Long> longList) {
        return DateVo.builder().date(LocalDateTime.now()).name("ddd").id(222L).localDateTime(DateUtil.parseLocalDateTime("2022-02-02 11:11:11")).build();
    }
}
